#选择排序
def selection_sort(A):
    n=len(A)
    for i in xrange(n-1):# the first n-1 elements
        smallest=A[i]
        s=i
        for j in xrange(i+1,n):
            if A[j]<smallest:
                smallest=A[j]
                s=j
        A[i],A[s]=A[s],A[i]
    return A

if __name__=='__main__':
    A=[11,5,2,6,77,23,8,4,123]
    print 'A=', A
    print 'result=', selection_sort(A)
